package com.model
{
	public class MenuXMLData
	{
		private static var menubarXML:XML =
			<root>
					<menu label="包围" name="body" >
							<menuItem id="m1" label="国产">
									<menuItem id="m1_1" label="大包围"/>
									<menuItem id="m1_2" label="小包围"/>
							</menuItem>
							<menuItem id="m2" label="台湾">
									<menuItem id="m2_1" label="大包围"/>
									<menuItem id="m2_2" label="小包围"/>
							</menuItem>
							<menuItem id="m3" label="德国">
									<menuItem id="m3_1" label="大包围"/>
									<menuItem id="m3_2" label="小包围"/>
							</menuItem>
					</menu>
					<menu label="尾翼" name="spoilers" >
							<menuItem id="m1" label="国产">
									<menuItem id="m1_1" label="大尾翼"/>
									<menuItem id="m1_2" label="小尾翼"/>
							</menuItem>
							<menuItem id="m2" label="台湾">
									<menuItem id="m2_1" label="大尾翼"/>
									<menuItem id="m2_2" label="小尾翼"/>
							</menuItem>
							<menuItem id="m3" label="德国">
									<menuItem id="m3_1" label="大尾翼"/>
									<menuItem id="m3_2" label="小尾翼"/>
							</menuItem>
					</menu>
					<menu label="轮毂" name="wheel" >
							<menuItem id="m1" label="国产">
									<menuItem id="m1_1" label="大轮毂"/>
									<menuItem id="m1_2" label="小轮毂"/>
							</menuItem>
							<menuItem id="m2" label="台湾">
									<menuItem id="m2_1" label="大轮毂"/>
									<menuItem id="m2_2" label="小轮毂"/>
							</menuItem>
							<menuItem id="m3" label="德国">
									<menuItem id="m3_1" label="大轮毂"/>
									<menuItem id="m3_2" label="小轮毂"/>
							</menuItem>
					</menu>
					<menu label="排气" name="ventpipe">
							<menuItem id="m1" label="国产">
									<menuItem id="m1_1" label="大排气"/>
									<menuItem id="m1_2" label="小排气"/>
							</menuItem>
							<menuItem id="m2" label="台湾">
									<menuItem id="m2_1" label="大排气"/>
									<menuItem id="m2_2" label="小排气"/>
							</menuItem>
							<menuItem id="m3" label="德国">
									<menuItem id="m3_1" label="大排气"/>
									<menuItem id="m3_2" label="小排气"/>
							</menuItem>
					</menu>
					<menu label="机盖" name="hood">
							<menuItem id="m1" label="国产">
									<menuItem id="m1_1" label="大机盖"/>
									<menuItem id="m1_2" label="小机盖"/>
							</menuItem>
							<menuItem id="m2" label="台湾">
									<menuItem id="m2_1" label="大机盖"/>
									<menuItem id="m2_2" label="小机盖"/>
							</menuItem>
							<menuItem id="m3" label="德国">
									<menuItem id="m3_1" label="大机盖"/>
									<menuItem id="m3_2" label="小机盖"/>
							</menuItem>
					</menu>
					<menu label="贴纸" name="stickers">
							<menuItem id="m1" label="国产">
									<menuItem id="m1_1" label="大贴纸"/>
									<menuItem id="m1_2" label="小贴纸"/>
							</menuItem>
							<menuItem id="m2" label="台湾">
									<menuItem id="m2_1" label="大贴纸"/>
									<menuItem id="m2_2" label="小贴纸"/>
							</menuItem>
							<menuItem id="m3" label="德国">
									<menuItem id="m3_1" label="大贴纸"/>
									<menuItem id="m3_2" label="小贴纸"/>
							</menuItem>
					</menu>
			</root>;
		
		/**
		 * 获取二级菜单数据 记录一级菜单索引值menuIndex关联数组
		 * {menuIndex:menuIndex,label:menuItem.@label}
		 * @param index
		 * @return 
		 */		
		public static function getMinorData(menuIndex:int):Array{
			var list:Array = [];
			var minorList:XMLList = getMenuList(menuIndex);
			for each (var menuItem:XML in minorList) 
			{
				list.push({menuIndex:menuIndex,label:String(menuItem.@label)});
			}
			return list;
		}
		/**
		 * 获取三级菜单数据 记录一级菜单索引值 记录id,label关联数组
		 * {menuIndex:menuIndex,id:menuItem.@id,label:menuItem.@label}
		 * @param index
		 * @return 
		 */	
		public static function getItemData(menuIndex:int,minorIndex:int):Array{
			var minorList:XMLList = getMenuList(menuIndex);
			var itemList:XMLList = minorList[minorIndex].menuItem;
			var list:Array = [];
			for each (var menuItem:XML in itemList) 
			{
				list.push({menuIndex:menuIndex,id:String(menuItem.@id),label:String(menuItem.@label)});
			}
			return list;
		}
		/**
		 * 最终通过索引值查找id数据来确定选中什么
		 * @param menuIndex
		 * @param minorIndex
		 * @param itemIndex
		 * @return 
		 */		
		public static function getItemId(menuIndex:int,minorIndex:int,itemIndex:int):String{
			return getMenuList(menuIndex)[minorIndex][itemIndex].@id;
		}
		
		/**
		 * 获取父容器的
		 */		
		public static function getParentItem(index:int,itemId:String):XML{
			var itemList:XMLList = getMenuList(index);
			var pId:String = itemId.split('_')[0];
			for each (var menuItem:XML in itemList) 
			{
				if(pId == menuItem.@id){
					return menuItem;
				}
			}
			return null;
		}
		/**
		 * 获取对应索引值的xmllist列表
		 * @return XMLList
		 */		
		public static function getMenuList(index:int):XMLList{
			return menubarXML.menu[index].menuItem;
		}
			
		public static function getMenuTitle(onTitle:Function):void{
			var menuList:XMLList = menubarXML.menu;
			for (var i:int = 0; i < menuList.length(); i++) 
			{
				onTitle(i,menuList[i].@label,menuList[i].@name);
			}
		}
		/**
		 * 获取一级菜单列表的功能
		 */	
		public static function getTitleList():Vector.<String>{
			var menuList:XMLList = menubarXML.menu;
			var mList:Vector.<String> = new Vector.<String>();
			for each (var menuItem:XML in menuList){
				mList.push(menuItem.@label);
			}
			return mList;
		}
		
		public static function get menuLength():int{
			return menubarXML.menu.length();
		}
		
		public static function getItemIDList(index:int):Vector.<String>{
			var idList:Vector.<String> = new Vector.<String>();
			var itemList:XMLList = getMenuList(index);
			for each (var menuItem:XML in itemList) 
			{
				for each (var childItem:XML in menuItem.menuItem) 
				{
					idList.push(childItem.@id);
				}
			}
			return idList;
		}
		
		
	}
}